//
//  CargoBoxViewController.m
//  OrderAssistant
//
//  Created by chendong on 2020/8/26.
//  Copyright © 2020 chendong. All rights reserved.
//

#import "CargoBoxViewController.h"
#import "CargoBoxTableViewCell.h"
#import "NetTools.h"
#import <SVProgressHUD.h>
#import "FCUUID.h"
#import <AFNetworking.h>
#import "HZAreaPickerView.h"
@interface CargoBoxViewController ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate,UITextFieldDelegate,UITextViewDelegate,HZAreaPickerDelegate,UITextViewDelegate>{
    UIAlertView *a1;
    UIAlertView *a2;
    UIAlertView *a3;
    UIAlertView *a5;
    UIAlertView *a6;
}
@property(nonatomic,strong) UITableView *myTableView;
@property(nonatomic,strong) UIView *remarkBgV;
@property(nonatomic,strong) UITextView *remarkTV;
@property(nonatomic,strong) UIView *mbV;
@property (nonatomic,strong) UIView *srBgV;
@property (nonatomic,strong) UITextField *srBgVTF;
@property (nonatomic,strong) UILabel *wlL;
@property (nonatomic,strong) CargoBoxTableViewCell *wlLCell;
@property (nonatomic,strong) NSIndexPath *wlLCellIndexPath;
@property (nonatomic,strong) UIAlertView *a4;
@property (nonatomic,assign) BOOL isTffff;
@property (nonatomic,strong) UIView *noView;
@property (nonatomic,strong) UIView *bottomBgV;
@property (nonatomic,strong) UIButton *lsddBtn;
@property (nonatomic,strong) UIButton *ksdhBtn;
@property (nonatomic,strong) UIButton *gwcBtn;
@property (nonatomic,assign) BOOL isreturn;
@property (nonatomic,copy) NSString *tvText;
@property (nonatomic,strong) NSMutableArray *tempArr;


@property (nonatomic,strong) UILabel *topPriceViewL;
@property (nonatomic,strong) UIView *tbheadGbV;

@property (nonatomic,strong) UIView *seleAdressBgV;
@property (nonatomic,strong) UITextField *addressName;
@property (nonatomic,strong) UITextField *addressTel;
@property (nonatomic,strong) UITextField *addressAddre;
@property (nonatomic,strong) UITextView *addressAddreinfo;
@property (nonatomic,strong) UILabel *addressAddreinfoL;

@property (strong, nonatomic) HZAreaPickerView *locatePicker;
@property (nonatomic,strong) UILabel *pl;
@property (nonatomic,strong) UILabel *xztxL;
@end

@implementation CargoBoxViewController
-(UIView *)tbheadGbV{
    if (!_tbheadGbV) {
        _tbheadGbV = [[UIView alloc]initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, SCREENWIDTH, 100)];
        _tbheadGbV.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:_tbheadGbV];
        UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(10, (_tbheadGbV.frame.size.height-32)/2, 32, 32)];
        imgV.image = [UIImage imageNamed:@"dingwei.png"];
        [_tbheadGbV addSubview:imgV];
        UILabel *qxzBtn = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(imgV.frame), 0, 250, _tbheadGbV.frame.size.height)];
        qxzBtn.userInteractionEnabled = YES;
        qxzBtn.text = @"先填写地址，再确认订单信息";
        qxzBtn.font = [UIFont systemFontOfSize:18 weight:200];
        qxzBtn.numberOfLines = 0;
        [_tbheadGbV addSubview:qxzBtn];
        self.addressAddreinfoL = qxzBtn;
        UIView *xztxBgV = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(qxzBtn.frame), (_tbheadGbV.frame.size.height-32)/2, _tbheadGbV.frame.size.width-CGRectGetMaxX(qxzBtn.frame), 32)];
        [_tbheadGbV addSubview:xztxBgV];
        UILabel *xztxL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, xztxBgV.frame.size.width-32, 32)];
        xztxL.text = @"现在填写";
        xztxL.textColor = RGBCOLOR(108, 185, 251);
        xztxL.textAlignment = NSTextAlignmentRight;
        [xztxBgV addSubview:xztxL];
        self.xztxL = xztxL;
        
        if ([NSString stringWithFormat:@"%@",self.userDic[@"OrganizationContactsUser"]].length>0) {
            NSMutableAttributedString * firstPart = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationContactsUser"]]];
                NSDictionary * firstAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16 weight:200],NSForegroundColorAttributeName:[UIColor blackColor]};
                [firstPart setAttributes:firstAttributes range:NSMakeRange(0, [NSString stringWithFormat:@"%@",self.userDic[@"OrganizationContactsUser"]].length)];
                NSMutableAttributedString * secondPart = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",[NSString stringWithFormat:@"%@",self.userDic[@"Tel"]]]];
                NSDictionary * secondAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor lightGrayColor]};
                [secondPart setAttributes:secondAttributes range:NSMakeRange(0,secondPart.length)];
                [firstPart appendAttributedString:secondPart];
            
                NSMutableAttributedString * secondPart1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n%@",[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationAddress"]]]];
                NSDictionary * secondAttributes1 = @{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor blackColor]};
                [secondPart1 setAttributes:secondAttributes1 range:NSMakeRange(0,secondPart1.length)];
                [firstPart appendAttributedString:secondPart1];
            self.addressAddreinfoL.attributedText = firstPart;
            xztxL.text = @"";
        }
        UIImageView *xzImgV = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(xztxL.frame), 0, 32, 32)];
        xzImgV.image = [UIImage imageNamed:@"youzhuan.png"];
        [xztxBgV addSubview:xzImgV];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(qxzBtnAction:)];
        [xztxBgV addGestureRecognizer:tap];
        NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"ipaddress"];
        if (str.length != 0) {
            _tbheadGbV.hidden = YES;
            _tbheadGbV = [[UIView alloc]initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, SCREENWIDTH, 0)];
        }
    }
    return _tbheadGbV;
}
-(void)textViewDidBeginEditing:(UITextView *)textView{
    if (textView == self.addressAddreinfo) {
        self.pl.hidden = YES;
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView{
    if (textView.text.length > 0) {
        self.pl.hidden = YES;
    }else{
        self.pl.hidden = NO;
    }
}
-(UIView *)seleAdressBgV{
    if (!_seleAdressBgV) {
        _seleAdressBgV = [[UIView alloc]initWithFrame:CGRectMake(0, SCREENHEIGHT, SCREENWIDTH, 600)];
        _seleAdressBgV.backgroundColor = [UIColor whiteColor];
        UIBezierPath*maskPath = [UIBezierPath bezierPathWithRoundedRect:_seleAdressBgV.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(20,20)];
        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.frame = _seleAdressBgV.bounds;
        maskLayer.path = maskPath.CGPath;
        _seleAdressBgV.layer.mask = maskLayer;
        [self.view.window addSubview:_seleAdressBgV];
        UIButton *cancalebBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        cancalebBtn.frame = CGRectMake(_seleAdressBgV.frame.size.width-40, 5, 32, 32);
        [cancalebBtn setImage:[UIImage imageNamed:@"login1.png"] forState:UIControlStateNormal];
        [cancalebBtn addTarget:self action:@selector(cancalebBtnaction:) forControlEvents:UIControlEventTouchUpInside];
        [_seleAdressBgV addSubview:cancalebBtn];
        
        NSArray *arr = @[@"收货人",@"手机号码",@"详细地址"];//,@"所在区域"
        NSArray *arrr = @[@"名字",@"手机号",@"详细地址"];//,@"省、市、区"
        int x = 20;
        int y = CGRectGetMaxY(cancalebBtn.frame);
        int w = _seleAdressBgV.frame.size.width-2*x;
        int h = 70;
        for (int i=0; i<arr.count; i++) {
            y = CGRectGetMaxY(cancalebBtn.frame) + h*i;
            UIView *v = [[UIView alloc]initWithFrame:CGRectMake(x, y, w, h)];
            if (i == arr.count-1) {
                v.frame = CGRectMake(x, y, w, h*2);
            }
            [_seleAdressBgV addSubview:v];
            UILabel *l = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 80, h-10)];
            l.font = [UIFont systemFontOfSize:18 weight:200];
            l.text = arr[i];
            [v addSubview:l];
            if (i==0) {
                UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(l.frame), l.frame.origin.y, v.frame.size.width-CGRectGetMaxX(l.frame), l.frame.size.height)];
                UIView *zwv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 7, 10)];
                tf.leftView = zwv;
                tf.leftViewMode = UITextFieldViewModeAlways;
                tf.placeholder = arrr[i];
                tf.backgroundColor = RGBCOLOR(240, 240, 240);
                tf.layer.cornerRadius = 10;
                tf.clipsToBounds = YES;
                [v addSubview:tf];
                tf.text = [NSString stringWithFormat:@"%@",self.userDic[@"OrganizationContactsUser"]].length>0?[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationContactsUser"]]:@"";
                self.addressName = tf;
            }else if(i==1){
                UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(l.frame), l.frame.origin.y, v.frame.size.width-CGRectGetMaxX(l.frame), l.frame.size.height)];
                UIView *zwv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 7, 10)];
                tf.leftView = zwv;
                tf.leftViewMode = UITextFieldViewModeAlways;
                tf.placeholder = arrr[i];
                tf.backgroundColor = RGBCOLOR(240, 240, 240);
                tf.layer.cornerRadius = 10;
                tf.clipsToBounds = YES;
                [v addSubview:tf];
                tf.text = [NSString stringWithFormat:@"%@",self.userDic[@"Tel"]].length>0?[NSString stringWithFormat:@"%@",self.userDic[@"Tel"]]:@"";
                self.addressTel = tf;
            }else if(i==2){
//                self.addressAddre = tf;
//                tf.delegate = self;
////                tf.enabled = NO;
////                tf.userInteractionEnabled = YES;
//                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cityAction:)];
//                [tf addGestureRecognizer:tap];
                UITextView *tf = [[UITextView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(l.frame), l.frame.origin.y, v.frame.size.width-CGRectGetMaxX(l.frame), v.frame.size.height-10)];
                tf.font = [UIFont systemFontOfSize:18];
//                UIView *zwv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 5, 10)];
//                tf.leftView = zwv;
//                tf.leftViewMode = UITextFieldViewModeAlways;
//                tf.placeholder = arrr[i];
                tf.backgroundColor = RGBCOLOR(240, 240, 240);
                tf.layer.cornerRadius = 10;
                tf.clipsToBounds = YES;
                tf.contentInset = UIEdgeInsetsMake(12, 5, 0, 0);
                tf.delegate = self;
                UILabel *pL = [[UILabel alloc]initWithFrame:CGRectMake(5, 6, 200, 30)];
                pL.text = @"请输入详细地址";
                pL.textColor = RGBCOLOR(195, 195, 195);
                [tf addSubview:pL];
                self.pl = pL;
                tf.text = [NSString stringWithFormat:@"%@",self.userDic[@"OrganizationAddress"]].length>0?[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationAddress"]]:@"";
                self.pl.hidden = tf.text.length>0?YES:NO;
                [v addSubview:tf];
                self.addressAddreinfo = tf;
            }else if(i==3){
//                self.addressAddreinfo = tf;
            }
            
//            if (i==3) {
//                y =
//            }else{
//                h = 70;
//            }
        }
        
        UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        saveBtn.frame = CGRectMake((_seleAdressBgV.frame.size.width-300)/2, _seleAdressBgV.frame.size.height-65, 300, 50);
        [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
        [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        saveBtn.titleLabel.font = [UIFont systemFontOfSize:20];
        saveBtn.backgroundColor = RGBCOLOR(108, 185, 251);
        saveBtn.layer.cornerRadius = 25;
        saveBtn.clipsToBounds = YES;
        [saveBtn addTarget:self action:@selector(saveBtnAAAAction:) forControlEvents:UIControlEventTouchUpInside];
        [_seleAdressBgV addSubview:saveBtn];
    }
    return _seleAdressBgV;
}
-(void)cityAction:(UITapGestureRecognizer *)tap{
    [self cancelLocatePicker];
    self.locatePicker = [[HZAreaPickerView alloc] initWithStyle:HZAreaPickerWithStateAndCityAndDistrict delegate:self];
    [self.locatePicker showInView:self.view.window];
}
#pragma mark - HZAreaPicker delegate
-(void)pickerDidChaneStatus:(HZAreaPickerView *)picker
{
    if (picker.pickerStyle == HZAreaPickerWithStateAndCityAndDistrict) {
        
    } else{
        
    }

}
-(void)cancelLocatePicker
{
    [self.locatePicker cancelPicker];
    self.locatePicker.delegate = nil;
    self.locatePicker = nil;
}
- (void)ensureClick{
    [self cancelLocatePicker];
}
-(void)saveBtnAAAAction:(UIButton *)btn{
    [UIView animateWithDuration:1.0f animations:^{
        CGRect r = self.seleAdressBgV.frame;
        r.origin.y = SCREENHEIGHT;
        self.seleAdressBgV.frame = r;
    } completion:^(BOOL finished) {
        self.mbV.hidden = YES;
    }];
    self.xztxL.hidden = YES;
    NSMutableAttributedString * firstPart = [[NSMutableAttributedString alloc] initWithString:self.addressName.text];
        NSDictionary * firstAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16 weight:200],NSForegroundColorAttributeName:[UIColor blackColor]};
        [firstPart setAttributes:firstAttributes range:NSMakeRange(0, self.addressName.text.length)];
        NSMutableAttributedString * secondPart = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",self.addressTel.text]];
        NSDictionary * secondAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor lightGrayColor]};
        [secondPart setAttributes:secondAttributes range:NSMakeRange(0,secondPart.length)];
        [firstPart appendAttributedString:secondPart];
    
        NSMutableAttributedString * secondPart1 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\n%@",self.addressAddreinfo.text]];
        NSDictionary * secondAttributes1 = @{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor blackColor]};
        [secondPart1 setAttributes:secondAttributes1 range:NSMakeRange(0,secondPart1.length)];
        [firstPart appendAttributedString:secondPart1];
    
//    self.addressAddreinfoL.text = [NSString stringWithFormat:@"%@ %@\n%@",self.addressName.text,self.addressTel.text,self.addressAddreinfo.text];
    self.addressAddreinfoL.attributedText = firstPart;
    
    //保存收货地址
    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"ipaddress"];
if (str.length == 0) {
    // 请求头
//    NSString *accessPath = @"http://192.168.0.19:80/Api/OrderGoods/UpdateReceivingInf";
                    NSString *accessPath = @"http://crm.zhenyea.com/Api/OrderGoods/UpdateReceivingInf";
    // 请求参数字典strOrganizationNo、strOrganizationContactsUser、strOrganizationAddress、strTel、strUserId、strUserName、strPassword、strIMEI
    //陈栋  18538003952 河南省新乡市土大力有限公司
    NSDictionary *params = @{
        @"strOrganizationNo":[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationNo"]],
        @"strOrganizationContactsUser":self.addressName.text,
        @"strOrganizationAddress":self.addressAddreinfo.text,
        @"strTel":self.addressTel.text,
        @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
        @"strUserName":[NSString stringWithFormat:@"%@",self.userDic[@"UserName"]],
        @"strPassword":[NSString stringWithFormat:@"%@",self.userDic[@"UserPass"]],
        @"strIMEI":[FCUUID uuidForVendor]
    };
    
    //创建配置信息
    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    //设置请求超时时间：5秒
    configuration.timeoutIntervalForRequest = 5;
    //创建会话
    NSURLSession *session = [NSURLSession sessionWithConfiguration: configuration delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",accessPath]]];
    //设置请求方式：POST
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/json" forHTTPHeaderField:@"content-Type"];
    [request setValue:@"application/json;charset=gb2312" forHTTPHeaderField:@"Accept"];
    
    //data的字典形式转化为data
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
    //设置请求体
    [request setHTTPBody:jsonData];
    
    NSURLSessionDataTask * dataTask =[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        [SVProgressHUD dismiss];
        if (error == nil) {
            NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
            NSString *receiveStr = [[NSString alloc]initWithData:data encoding:encoding];
            NSData * aData = [receiveStr dataUsingEncoding:NSUTF8StringEncoding];
            NSError *errorr = nil;
            id response = [NSJSONSerialization JSONObjectWithData:aData options:NSJSONReadingMutableContainers error:&errorr];
            if ([response isKindOfClass:[NSDictionary class]]) {
                // 请求成功数据处理
                NSString *IsResult = [NSString stringWithFormat:@"%@",[response objectForKey:@"IsResult"]];
                if ([IsResult isEqualToString:@"1"]) {
                    
                }else{
                    UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",response[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                    [vv show];
                }
            } else {
                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                [vv show];
            }
        }else{
            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
            [vv show];
        }
    }];
    [dataTask resume];
}else{
    [NetTools postWithUrl:
     [NSString stringWithFormat:@"http://%@/ldcy/OrderGoods/OrderGoods.asmx/UpdateReceivingInf",str] pararms:@{}
         success:^(id  _Nonnull json) {
            if ([[NSString stringWithFormat:@"%@",json[@"IsResult"]] isEqualToString:@"1"]) {
                [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"remarkeeee"];
                [[NSUserDefaults standardUserDefaults] synchronize];
                self.a4.title = [NSString stringWithFormat:@"%@",json[@"Message"]];
                [self.a4 show];
            }else{
                UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",json[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                [vv show];
            }
        } fail:^(NSError * _Nonnull error) {
            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
//                            NSLog(@"服务器的错误原因:%@",str);
            UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
            [vv show];
            
        }];
}
    
}
-(void)cancalebBtnaction:(UIButton *)btn{
    [UIView animateWithDuration:1.0f animations:^{
        CGRect r = self.seleAdressBgV.frame;
        r.origin.y = SCREENHEIGHT;
        self.seleAdressBgV.frame = r;
    } completion:^(BOOL finished) {
        self.mbV.hidden = YES;
    }];
}
-(float)elePrice{
    NSString *str = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"IsShowPrice"]];
    if ([str isEqualToString:@"0"]) {
        return 0;
    }
    float z = 0;
    for (int i=0; i<self.dataMarr.count; i++) {
        z += [self.dataMarr[i][@"MaterialNum"] floatValue]*[self.dataMarr[i][@"MaterialPrice"] floatValue];
    }
    return z;
}
-(UILabel *)topPriceViewL{
    if (!_topPriceViewL) {
        _topPriceViewL = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tbheadGbV.frame)+5, SCREENWIDTH, 50)];
        _topPriceViewL.backgroundColor = [UIColor whiteColor];
        _topPriceViewL.text = [NSString stringWithFormat:@"金额：¥%.2f",[self elePrice]];
        _topPriceViewL.textAlignment = NSTextAlignmentRight;
        _topPriceViewL.textColor = [UIColor blackColor];
        /// 线的路径
//        UIBezierPath * bezierPath = [UIBezierPath bezierPath];
//        /// bottom线路径
//        [bezierPath moveToPoint:CGPointMake(0.0f, _topPriceViewL.frame.size.height)];
//        [bezierPath addLineToPoint:CGPointMake( _topPriceViewL.frame.size.width, _topPriceViewL.frame.size.height)];
//        CAShapeLayer * shapeLayer = [CAShapeLayer layer];
//            shapeLayer.strokeColor = [UIColor lightGrayColor].CGColor;
//            shapeLayer.fillColor  = [UIColor clearColor].CGColor;
//            /// 添加路径
//            shapeLayer.path = bezierPath.CGPath;
//            /// 线宽度
//            shapeLayer.lineWidth = 1;
//
//            [_topPriceViewL.layer addSublayer:shapeLayer];
        _topPriceViewL.hidden = [[NSUserDefaults standardUserDefaults] objectForKey:@"IsShowPrice"]?NO:YES;
        NSString *str = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"IsShowPrice"]];
        if ([str isEqualToString:@"0"]) {
            _topPriceViewL.hidden = YES;
        }
        [self.view addSubview:_topPriceViewL];
    }
    return _topPriceViewL;
}
-(NSMutableArray *)tempArr{
    if (!_tempArr) {
        _tempArr = [[NSMutableArray alloc]init];
    }
    return _tempArr;
}
-(void)textViewDidChange:(UITextView *)textView{
    if (self.oid.length>0) {
        if ([textView.text isEqualToString:self.tvText]) {
            self.isreturn = NO;
        }else{
            self.isreturn = YES;
        }
    }
}
-(UIView *)noView{
    if (!_noView) {
        _noView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT-self.bottomBgV.frame.size.height)];
        _noView.backgroundColor = RGBCOLOR(230, 230, 230);
        [self.view addSubview:_noView];
        UIImageView *noIMGv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 115, 115)];
        noIMGv.center = CGPointMake(_noView.frame.size.width/2, _noView.frame.size.height/2);
        noIMGv.image = [UIImage imageNamed:@"icon_empty.png"];
        [_noView addSubview:noIMGv];
        UILabel *lllll = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(noIMGv.frame), SCREENWIDTH, 50)];
        lllll.text = @"空空如也";
        lllll.textAlignment = NSTextAlignmentCenter;
        lllll.textColor = RGBCOLOR(181, 181, 181);
        [_noView addSubview:lllll];
    }
    return _noView;
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    if (textField == self.addressAddre) {
        return NO;
    }
    return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [self.srBgVTF performSelector:@selector(selectAll:) withObject:nil afterDelay:.0f];
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField == self.srBgVTF && self.isTffff) {
        textField.text = @"";
        self.isTffff = NO;
    }
    if (textField == self.srBgVTF) {
        if ([string isEqualToString:@"."]) {
            if (textField.text.length == 0 || [textField.text containsString:@"."]) {
                return NO;
            }
        }
    }
    return YES;
}
- (UIAlertView *)a4{
    if (!_a4) {
        _a4 = [[UIAlertView alloc] initWithTitle:@"下单成功！" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    }
    return _a4;
}
-(UIView *)mbV{
    if (!_mbV) {
        _mbV = [[UIView alloc]initWithFrame:self.view.bounds];
        _mbV.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        [self.view.window addSubview:_mbV];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(mbVAction:)];
        [_mbV addGestureRecognizer:tap];
    }
    return _mbV;
}
-(void)mbVAction:(UITapGestureRecognizer *)tap{
    [self.view endEditing:YES];
}
-(UIView *)srBgV{
    if (!_srBgV) {
        _srBgV = [[UIView alloc]initWithFrame:CGRectMake(50, 0, SCREENWIDTH-100, 200)];
        _srBgV.center = CGPointMake(SCREENWIDTH/2, SCREENHEIGHT/2);
        _srBgV.backgroundColor = [UIColor whiteColor];
        _srBgV.layer.cornerRadius = 5;
        _srBgV.clipsToBounds = YES;
        [self.view.window addSubview:_srBgV];
        UILabel *titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, 25, _srBgV.frame.size.width, 50)];
        titleL.text = @"请输入数量";
        titleL.font = [UIFont systemFontOfSize:20];
        titleL.textAlignment = NSTextAlignmentCenter;
        [_srBgV addSubview:titleL];
        self.wlL = titleL;
        UILabel *slL = [[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(titleL.frame), 0, 50)];
        slL.text = @"数量";
        [_srBgV addSubview:slL];
        UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(slL.frame), CGRectGetMaxY(titleL.frame), _srBgV.frame.size.width-10-CGRectGetMaxX(slL.frame), 50)];
        tf.delegate = self;
        tf.keyboardType = UIKeyboardTypeDecimalPad;
        tf.layer.borderWidth = 1;
        tf.layer.borderColor = [UIColor lightGrayColor].CGColor;
        tf.layer.cornerRadius = 5;
        tf.clipsToBounds = YES;
        tf.placeholder = @"请输入数量";
        UIView *lV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 50)];
        tf.leftView = lV;
        tf.leftViewMode = UITextFieldViewModeAlways;
        [_srBgV addSubview:tf];
        self.srBgVTF = tf;
        UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        cancleBtn.frame = CGRectMake(10, CGRectGetMaxY(tf.frame)+15, _srBgV.frame.size.width/2-20, 40);
        cancleBtn.layer.cornerRadius = 5;
        cancleBtn.clipsToBounds = YES;
        [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        cancleBtn.backgroundColor = RGBCOLOR(108, 185, 251);
        [_srBgV addSubview:cancleBtn];
        [cancleBtn addTarget:self action:@selector(sscancleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *quedingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        quedingBtn.frame = CGRectMake(CGRectGetMaxX(cancleBtn.frame)+20, CGRectGetMaxY(tf.frame)+15, _srBgV.frame.size.width/2-20, 40);
        quedingBtn.layer.cornerRadius = 5;
        quedingBtn.clipsToBounds = YES;
        [quedingBtn setTitle:@"确定" forState:UIControlStateNormal];
        [quedingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        quedingBtn.backgroundColor = RGBCOLOR(108, 185, 251);
        [_srBgV addSubview:quedingBtn];
        [quedingBtn addTarget:self action:@selector(ssquedingBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _srBgV;
}
-(void)sscancleBtnAction:(UIButton *)btn{
    self.mbV.hidden = YES;
    self.srBgV.hidden = YES;
    self.srBgVTF.text = @"";
    [self.view.window endEditing:YES];
}
-(void)ssquedingBtnAction:(UIButton *)btn{
    [self.view.window endEditing:YES];
    if (self.srBgVTF.text.length <= 0) {
        self.srBgVTF.text = @"";
        self.mbV.hidden = YES;
        self.srBgV.hidden = YES;
        return;
    }
    if ([self.srBgVTF.text hasSuffix:@"."]) {
        self.srBgVTF.text = [[self.srBgVTF.text componentsSeparatedByString:@"."] firstObject];
    }
    
    NSDictionary *d = self.wlLCell.dic;
    NSDictionary *dd = self.houseDic;
    NSString *IsUseAuxiliaryUnit = [NSString stringWithFormat:@"%@",self.houseDic[@"IsUseAuxiliaryUnit"]];
    int bl = [[[[NSString stringWithFormat:@"%@",d[@"ConvertUnit"]] componentsSeparatedByString:@":"] firstObject] floatValue];
    if ([IsUseAuxiliaryUnit isEqualToString:@"1"]) {
        if ([self.srBgVTF.text intValue]%bl == 0) {
            self.wlLCell.cdxdbmL.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":self.srBgVTF.text;
        }else{
            NSString *finS = [NSString stringWithFormat:@"%d",([self.srBgVTF.text intValue]/bl + 1)*bl];
            self.wlLCell.cdxdbmL.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":finS;
            
            [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
            [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@的数量必须是%d的倍数",self.wlLCell.dic[@"MaterialName"],bl]];
            
            self.srBgVTF.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":finS;
        }
    }else{
        self.wlLCell.cdxdbmL.text = [self.srBgVTF.text isEqualToString:@"0"]?@"":self.srBgVTF.text;
    }
    
    for (int i=0; i<self.dataMarr.count; i++) {
        if ([[NSString stringWithFormat:@"%@",self.wlLCell.dic[@"MaterialID"]] isEqualToString:[NSString stringWithFormat:@"%@",self.dataMarr[i][@"MaterialID"]]]) {
            NSDictionary *ddd = self.dataMarr[i];
            [ddd setValue:self.srBgVTF.text forKey:@"MaterialNum"];
            if ([self.srBgVTF.text isEqualToString:@"0"]) {
                [self.dataMarr removeObject:self.dataMarr[i]];
            }
            break;
        }
        if (i==self.dataMarr.count-1 && ![self.srBgVTF.text isEqualToString:@"0"]) {
            NSDictionary *ddd = self.wlLCell.dic;
            [ddd setValue:self.srBgVTF.text forKey:@"MaterialNum"];
            [self.dataMarr addObject:ddd];
            
        }
    }
    if (self.dataMarr.count == 0 && ![self.srBgVTF.text isEqualToString:@"0"]) {
        NSDictionary *ddd = self.wlLCell.dic;
        [ddd setValue:self.srBgVTF.text forKey:@"MaterialNum"];
        [self.dataMarr addObject:ddd];
    }
    if ([self.srBgVTF.text isEqualToString:@"0"]) {
        self.wlLCell.jianBtn.hidden = YES;
        self.wlLCell.pluseBtn.selected = NO;
    }else{
        self.wlLCell.jianBtn.hidden = NO;
        self.wlLCell.jianBtn.selected = YES;
        self.wlLCell.pluseBtn.selected = YES;
    }
    
    self.wlLCell.xdbmLu.text = [NSString stringWithFormat:@"小计：¥%.2f",[self.srBgVTF.text floatValue] * [[NSString stringWithFormat:@"%@",self.wlLCell.dic[@"MaterialPrice"]] floatValue]];
    self.srBgVTF.text = @"";
    self.mbV.hidden = YES;
    self.srBgV.hidden = YES;
    
    if (self.oid.length <= 0) {
        [self creatPlist];
    }
    
    self.topPriceViewL.text = [NSString stringWithFormat:@"金额：%.2f元",[self elePrice]];
}
-(UIView *)remarkBgV{
    if (!_remarkBgV) {
        _remarkBgV = [[UIView alloc]initWithFrame:CGRectMake(50, 0, SCREENWIDTH-100, 380)];
        _remarkBgV.center = CGPointMake(SCREENWIDTH/2, SCREENHEIGHT/2);
        _remarkBgV.backgroundColor = [UIColor whiteColor];
        _remarkBgV.layer.cornerRadius = 5;
        _remarkBgV.clipsToBounds = YES;
        [self.view.window addSubview:_remarkBgV];
        UILabel *titleL = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, _remarkBgV.frame.size.width, 50)];
        titleL.text = @"备注";
        titleL.textAlignment = NSTextAlignmentCenter;
        [_remarkBgV addSubview:titleL];
//        self.wlL = titleL;
        UITextView *tf = [[UITextView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(titleL.frame), _remarkBgV.frame.size.width-20, 250)];
        tf.delegate = self;
        tf.font = [UIFont systemFontOfSize:15];
        tf.layer.borderWidth = 1;
        tf.layer.borderColor = [UIColor lightGrayColor].CGColor;
        tf.layer.cornerRadius = 5;
        tf.clipsToBounds = YES;
        
        NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"remarkeeee"];
        tf.text = str.length==0?@"":str;
//        tf.placeholder = @"请输入数量";
//        UIView *lV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 50)];
//        tf.leftView = lV;
//        tf.leftViewMode = UITextFieldViewModeAlways;
        [_remarkBgV addSubview:tf];
        self.remarkTV = tf;
        UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        cancleBtn.frame = CGRectMake(10, CGRectGetMaxY(tf.frame)+20, _remarkBgV.frame.size.width/2-20, 40);
        cancleBtn.layer.cornerRadius = 5;
        cancleBtn.clipsToBounds = YES;
        [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        cancleBtn.backgroundColor = RGBCOLOR(108, 185, 251);
        [_remarkBgV addSubview:cancleBtn];
        [cancleBtn addTarget:self action:@selector(cancleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *quedingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        quedingBtn.frame = CGRectMake(CGRectGetMaxX(cancleBtn.frame)+20, CGRectGetMaxY(tf.frame)+20, _remarkBgV.frame.size.width/2-20, 40);
        quedingBtn.layer.cornerRadius = 5;
        quedingBtn.clipsToBounds = YES;
        [quedingBtn setTitle:@"确定" forState:UIControlStateNormal];
        [quedingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        quedingBtn.backgroundColor = RGBCOLOR(108, 185, 251);
        [_remarkBgV addSubview:quedingBtn];
        [quedingBtn addTarget:self action:@selector(quedingBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _remarkBgV;
}
-(void)cancleBtnAction:(UIButton *)btn{
    self.mbV.hidden = YES;
    self.remarkBgV.hidden = YES;
    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"remarkeeee"];
    self.remarkTV.text = str;
    [self.view.window endEditing:YES];
}
-(void)quedingBtnAction:(UIButton *)btn{
    self.mbV.hidden = YES;
    self.remarkBgV.hidden = YES;
    [[NSUserDefaults standardUserDefaults] setObject:self.remarkTV.text forKey:@"remarkeeee"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [self.view.window endEditing:YES];
}
-(UITableView *)myTableView{
    if (!_myTableView) {
        if ([[NSUserDefaults standardUserDefaults] objectForKey:@"IsShowPrice"]) {
            NSString *str = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"IsShowPrice"]];
            if ([str isEqualToString:@"0"]) {
                _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tbheadGbV.frame), SCREENWIDTH, SCREENHEIGHT-kTabBarHeight-20-CGRectGetMaxY(self.tbheadGbV.frame)) style:UITableViewStylePlain];
            }else{
                _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.topPriceViewL.frame)+5, SCREENWIDTH, SCREENHEIGHT-kTabBarHeight-20-CGRectGetMaxY(self.topPriceViewL.frame)) style:UITableViewStylePlain];
            }
        }else{
            _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT-kTabBarHeight-20) style:UITableViewStylePlain];
        }
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        [self.view addSubview:_myTableView];
    }
    return _myTableView;
}
-(void)qxzBtnAction:(UITapGestureRecognizer *)btn{
    self.mbV.hidden = NO;
    [UIView animateWithDuration:1.0f animations:^{
        CGRect r = self.seleAdressBgV.frame;
        r.origin.y = SCREENHEIGHT-r.size.height;
        self.seleAdressBgV.frame = r;
    }];
}
-(void)rightAction:(UIButton *)btn{
    a1 = [[UIAlertView alloc] initWithTitle:nil message:@"确定清空货筐么？" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    a1.delegate = self;
    [a1 show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView == a1) {
        if (buttonIndex == 1) {
            [self.dataMarr removeAllObjects];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"changeee" object:nil];
//            [self.navigationController popViewControllerAnimated:YES];
            self.myTableView.hidden = YES;
            self.noView.hidden = NO;
            self.ksdhBtn.backgroundColor = RGBCOLOR(150, 150, 150);
            self.lsddBtn.backgroundColor = RGBCOLOR(150, 150, 150);
            self.ksdhBtn.enabled = NO;
            self.lsddBtn.enabled = NO;
            self.gwcBtn.enabled = NO;
        }
    }else if (alertView == a2){
        if (buttonIndex == 1) {

                for (int i=0; i<self.dataMarr.count; i++) {
                    if ([[NSString stringWithFormat:@"%@",self.wlLCell.dic[@"MaterialID"]] isEqualToString:[NSString stringWithFormat:@"%@",self.dataMarr[i][@"MaterialID"]]]) {
                        NSDictionary *ddd = self.dataMarr[i];
                        [ddd setValue:@"0" forKey:@"MaterialNum"];
                        [self.dataMarr removeObject:self.dataMarr[i]];
                        
                        break;
                    }
                    if (i==self.dataMarr.count-1) {
                        NSDictionary *ddd = self.wlLCell.dic;
                        [ddd setValue:@"0" forKey:@"MaterialNum"];
                        [self.dataMarr addObject:ddd];
                    }
                }
                if (self.wlLCellIndexPath.row == self.dataMarr.count-1) {
                    [self.myTableView reloadData];
                }else{
                    [self.myTableView reloadData];
                }
                if (self.dataMarr.count == 0 && self.oid.length == 0) {
                    self.myTableView.hidden = YES;
                    self.noView.hidden = NO;
                    self.ksdhBtn.backgroundColor = RGBCOLOR(150, 150, 150);
                    self.lsddBtn.backgroundColor = RGBCOLOR(150, 150, 150);
                    self.ksdhBtn.enabled = NO;
                    self.lsddBtn.enabled = NO;
                    self.gwcBtn.enabled = NO;
                }
                self.topPriceViewL.text = [NSString stringWithFormat:@"金额：%.2f元",[self elePrice]];
                [self creatPlist];
            
            if (self.oid.length > 0) {
                self.isreturn = YES;
                if (self.dataMarr.count == 0 && self.oid > 0) {
                    a6 = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您已删除所有物料，点击[确定]将删除此订单！" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
                    a6.delegate = self;
                    [a6 show];
                }
            }
            
            }
    }else if (alertView == a3){
        if (buttonIndex == 0) {
            if (self.oid.length>0) {
                    //下单
                    NSData *d = [NSJSONSerialization dataWithJSONObject:self.dataMarr options:NSJSONWritingPrettyPrinted error:nil];
                    NSString *dataStrr = [[NSString alloc]initWithData:d encoding:NSUTF8StringEncoding];
                    NSDictionary *dic = @{
                        @"strRemark":self.remarkTV.text.length > 0 ? self.remarkTV.text:@"",
                        @"strOrderID":[NSString stringWithFormat:@"%@",self.editDicccc[@"OrderID"]],
                        @"strUserName":[NSString stringWithFormat:@"%@",self.userDic[@"UserName"]],
                        @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                        @"OrderDetails":dataStrr
                    };
                    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"ipaddress"];
                if (str.length == 0) {
                    // 请求头
//                    NSString *accessPath = @"http://192.168.0.19:80/Api/OrderGoods/UpdateOrder";
                    NSString *accessPath = @"http://crm.zhenyea.com/Api/OrderGoods/UpdateOrder";
                    // 请求参数字典
                    NSDictionary *params = @{
                        @"strOrganizationNo":[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationNo"]],
                        @"strPassword":[NSString stringWithFormat:@"%@",self.userDic[@"UserPass"]],
                        @"strIMEI":[FCUUID uuidForVendor],
                        @"strRemark":self.remarkTV.text.length > 0 ? self.remarkTV.text:@"",
                        @"strOrderID":[NSString stringWithFormat:@"%@",self.editDicccc[@"OrderID"]],
                        @"strUserName":[NSString stringWithFormat:@"%@",self.userDic[@"UserName"]],
                        @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                        @"OrderDetails":dataStrr
                    };
                    
                    //创建配置信息
                    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
                    //设置请求超时时间：5秒
                    configuration.timeoutIntervalForRequest = 5;
                    //创建会话
                    NSURLSession *session = [NSURLSession sessionWithConfiguration: configuration delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
                    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",accessPath]]];
                    //设置请求方式：POST
                    [request setHTTPMethod:@"POST"];
                    [request setValue:@"application/json" forHTTPHeaderField:@"content-Type"];
                    [request setValue:@"application/json;charset=gb2312" forHTTPHeaderField:@"Accept"];
                    
                    //data的字典形式转化为data
                    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
                    //设置请求体
                    [request setHTTPBody:jsonData];
                    
                    NSURLSessionDataTask * dataTask =[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                        [SVProgressHUD dismiss];
                        if (error == nil) {
                            NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
                            NSString *receiveStr = [[NSString alloc]initWithData:data encoding:encoding];
                            NSData * aData = [receiveStr dataUsingEncoding:NSUTF8StringEncoding];
                            NSError *errorr = nil;
                            id response = [NSJSONSerialization JSONObjectWithData:aData options:NSJSONReadingMutableContainers error:&errorr];
                            if ([response isKindOfClass:[NSDictionary class]]) {
                                // 请求成功数据处理
                                NSString *IsResult = [NSString stringWithFormat:@"%@",[response objectForKey:@"IsResult"]];
                                if ([IsResult isEqualToString:@"1"]) {
                                    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"remarkeeee"];
                                    [[NSUserDefaults standardUserDefaults] synchronize];
                                    [self.a4 show];
                                }else{
                                    UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",response[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                    [vv show];
                                }
                            } else {
                                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                                UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                [vv show];
                            }
                        }else{
                            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                            UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                            [vv show];
                        }
                    }];
                    [dataTask resume];
                }else{
                    [NetTools postWithUrl:
                    [NSString stringWithFormat:@"http://%@/ldcy/OrderGoods/OrderGoods.asmx/UpdateOrder",str] pararms:dic
                         success:^(id  _Nonnull json) {
                            if ([[NSString stringWithFormat:@"%@",json[@"IsResult"]] isEqualToString:@"1"]) {
                                [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"remarkeeee"];
                                [[NSUserDefaults standardUserDefaults] synchronize];
                                self.a4.title = [NSString stringWithFormat:@"%@",json[@"Message"]];
                                [self.a4 show];
                            }else{
                                UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",json[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                [vv show];
                            }
                        } fail:^(NSError * _Nonnull error) {
                            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
//                            NSLog(@"服务器的错误原因:%@",str);
                            UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                            [vv show];
                            
                        }];
                }
                    
            }else{
                //下单
                    NSData *d = [NSJSONSerialization dataWithJSONObject:self.dataMarr options:NSJSONWritingPrettyPrinted error:nil];
                    NSString *dataStrr = [[NSString alloc]initWithData:d encoding:NSUTF8StringEncoding];
                    NSDictionary *dic = @{
                        @"strOrganizationNo":[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationNo"]],
                        @"strRemark":self.remarkTV.text.length > 0 ? self.remarkTV.text:@"",
                        @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                        @"strUserName":[NSString stringWithFormat:@"%@",self.userDic[@"UserName"]],
                        @"strNameNo":[NSString stringWithFormat:@"%@",self.houseDic[@"NameNo"]],
                        @"strWarehouse":[NSString stringWithFormat:@"%@",self.houseDic[@"Warehouse"]],
                        @"OrderDetails":dataStrr
                    };
                    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"ipaddress"];
                if (str.length == 0) {
                    // 请求头
//                    NSString *accessPath = @"http://192.168.0.19:80/Api/OrderGoods/InsertOrder";
                    NSString *accessPath = @"http://crm.zhenyea.com/Api/OrderGoods/InsertOrder";
                    // 请求参数字典
                    NSDictionary *params = [[NSDictionary alloc]init];
                    NSString *str = [NSString stringWithFormat:@"%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"IsShowPrice"]];
                    if ([str isEqualToString:@"0"]) {
                        params = @{
                            @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                            @"strPassword":[NSString stringWithFormat:@"%@",self.userDic[@"UserPass"]],
                            @"strIMEI":[FCUUID uuidForVendor],
                            @"strOrganizationNo":[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationNo"]],
                            @"strRemark":self.remarkTV.text.length > 0 ? self.remarkTV.text:@"",
                            @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                            @"strUserName":[NSString stringWithFormat:@"%@",self.userDic[@"UserName"]],
                            @"strNameNo":[NSString stringWithFormat:@"%@",self.houseDic[@"NameNo"]],
                            @"strWarehouse":[NSString stringWithFormat:@"%@",self.houseDic[@"Warehouse"]],
                            @"OrderDetails":dataStrr,
                            @"strAmount":[NSString stringWithFormat:@"%.2f",[self elePrice]]
                        };
                    }else{
                        params = @{
                            @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                            @"strPassword":[NSString stringWithFormat:@"%@",self.userDic[@"UserPass"]],
                            @"strIMEI":[FCUUID uuidForVendor],
                            @"strOrganizationNo":[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationNo"]],
                            @"strRemark":self.remarkTV.text.length > 0 ? self.remarkTV.text:@"",
                            @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                            @"strUserName":[NSString stringWithFormat:@"%@",self.userDic[@"UserName"]],
                            @"strNameNo":[NSString stringWithFormat:@"%@",self.houseDic[@"NameNo"]],
                            @"strWarehouse":[NSString stringWithFormat:@"%@",self.houseDic[@"Warehouse"]],
                            @"OrderDetails":dataStrr,
                            @"strAmount":[NSString stringWithFormat:@"%.2f",[self elePrice]]
                        };
                    }

                    //创建配置信息
                    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
                    //设置请求超时时间：5秒
                    configuration.timeoutIntervalForRequest = 5;
                    //创建会话
                    NSURLSession *session = [NSURLSession sessionWithConfiguration: configuration delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
                    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",accessPath]]];
                    //设置请求方式：POST
                    [request setHTTPMethod:@"POST"];
                    [request setValue:@"application/json" forHTTPHeaderField:@"content-Type"];
                    [request setValue:@"application/json;charset=gb2312" forHTTPHeaderField:@"Accept"];
                    
                    //data的字典形式转化为data
                    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
                    //设置请求体
                    [request setHTTPBody:jsonData];
                    
                    NSURLSessionDataTask * dataTask =[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                        [SVProgressHUD dismiss];
                        if (error == nil) {
                            NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
                            NSString *receiveStr = [[NSString alloc]initWithData:data encoding:encoding];
                            NSData * aData = [receiveStr dataUsingEncoding:NSUTF8StringEncoding];
                            NSError *errorr = nil;
                            id response = [NSJSONSerialization JSONObjectWithData:aData options:NSJSONReadingMutableContainers error:&errorr];
                            if ([response isKindOfClass:[NSDictionary class]]) {
                                // 请求成功数据处理
                                NSString *IsResult = [NSString stringWithFormat:@"%@",[response objectForKey:@"IsResult"]];
                                if ([IsResult isEqualToString:@"1"]) {
                                    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"remarkeeee"];
                                    [[NSUserDefaults standardUserDefaults] synchronize];
                                    [self.a4 show];
                                }else{
                                    UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",response[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                    [vv show];
                                }
                            } else {
                                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                                UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                [vv show];
                            }
                        }else{
                            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                            UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                            [vv show];
                        }
                    }];
                    [dataTask resume];
                }else{
                        [NetTools postWithUrl:
                        [NSString stringWithFormat:@"http://%@/ldcy/OrderGoods/OrderGoods.asmx/InsertOrder",str] pararms:dic
                             success:^(id  _Nonnull json) {
                                if ([[NSString stringWithFormat:@"%@",json[@"IsResult"]] isEqualToString:@"1"]) {
                                    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"remarkeeee"];
                                    [[NSUserDefaults standardUserDefaults] synchronize];
                                    [self.a4 show];
                                }else{
                                    UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",json[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                    [vv show];
                                }
                            } fail:^(NSError * _Nonnull error) {
                                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    //                            NSLog(@"服务器的错误原因:%@",str);
                                UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                [vv show];
                                
                            }];
                        }
                            
                    }
                }
                    
    }else if (alertView == self.a4){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"xiadanle" object:nil];
        if (self.oid.length>0) {
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }else if (alertView == a5){
        if (buttonIndex == 0) {
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else if (alertView == a6){
        if (buttonIndex == 1) {
            if (self.dataMarr.count == 0 && self.oid.length > 0) {
                self.noView.hidden = NO;
                //下单
                NSData *d = [NSJSONSerialization dataWithJSONObject:self.dataMarr options:NSJSONWritingPrettyPrinted error:nil];
                NSString *dataStrr = [[NSString alloc]initWithData:d encoding:NSUTF8StringEncoding];
                NSDictionary *dic = @{
                    @"strRemark":self.remarkTV.text.length > 0 ? self.remarkTV.text:@"",
                    @"strOrderID":[NSString stringWithFormat:@"%@",self.editDicccc[@"OrderID"]],
                    @"strUserName":[NSString stringWithFormat:@"%@",self.userDic[@"UserName"]],
                    @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                    @"OrderDetails":@""
                };
                NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"ipaddress"];
                if (str.length == 0) {
                    // 请求头
                    NSString *accessPath = @"http://www.zhenyea.com/WXSMTest/Api/OrderGoods/UpdateOrder";
                    // 请求参数字典
                    NSDictionary *params = @{
                        @"strOrganizationNo":[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationNo"]],
                        @"strPassword":[NSString stringWithFormat:@"%@",self.userDic[@"UserPass"]],
                        @"strIMEI":[FCUUID uuidForVendor],
                        @"strRemark":self.remarkTV.text.length > 0 ? self.remarkTV.text:@"",
                        @"strOrderID":[NSString stringWithFormat:@"%@",self.editDicccc[@"OrderID"]],
                        @"strUserName":[NSString stringWithFormat:@"%@",self.userDic[@"UserName"]],
                        @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
                        @"OrderDetails":dataStrr
                    };
                    
                    //创建配置信息
                    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
                    //设置请求超时时间：5秒
                    configuration.timeoutIntervalForRequest = 5;
                    //创建会话
                    NSURLSession *session = [NSURLSession sessionWithConfiguration: configuration delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
                    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",accessPath]]];
                    //设置请求方式：POST
                    [request setHTTPMethod:@"POST"];
                    [request setValue:@"application/json" forHTTPHeaderField:@"content-Type"];
                    [request setValue:@"application/json;charset=gb2312" forHTTPHeaderField:@"Accept"];
                    
                    //data的字典形式转化为data
                    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
                    //设置请求体
                    [request setHTTPBody:jsonData];
                    
                    NSURLSessionDataTask * dataTask =[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                        [SVProgressHUD dismiss];
                        if (error == nil) {
                            NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
                            NSString *receiveStr = [[NSString alloc]initWithData:data encoding:encoding];
                            NSData * aData = [receiveStr dataUsingEncoding:NSUTF8StringEncoding];
                            NSError *errorr = nil;
                            id response = [NSJSONSerialization JSONObjectWithData:aData options:NSJSONReadingMutableContainers error:&errorr];
                            if ([response isKindOfClass:[NSDictionary class]]) {
                                // 请求成功数据处理
                                NSString *IsResult = [NSString stringWithFormat:@"%@",[response objectForKey:@"IsResult"]];
                                if ([IsResult isEqualToString:@"1"]) {
                                    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"remarkeeee"];
                                    [[NSUserDefaults standardUserDefaults] synchronize];
                                    [self.a4 show];
                                }else{
                                    UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",response[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                    [vv show];
                                }
                            } else {
                                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                                UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                [vv show];
                            }
                        }else{
                            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                            UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                            [vv show];
                        }
                    }];
                    [dataTask resume];

//                    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
//
//                    NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:accessPath parameters:params error:nil];
//                    request.timeoutInterval = 10.f;
//                    [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//                    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//
//                    NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
//                        [SVProgressHUD dismiss];
//                        if (!error) {
//                            if ([responseObject isKindOfClass:[NSDictionary class]]) {
//                                // 请求成功数据处理
//                                NSString *IsResult = [NSString stringWithFormat:@"%@",[responseObject objectForKey:@"IsResult"]];
//                                if ([IsResult isEqualToString:@"1"]) {
//                                    [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"remarkeeee"];
//                                    [[NSUserDefaults standardUserDefaults] synchronize];
//                                    [self.a4 show];
//                                }else{
//                                    UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",responseObject[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
//                                    [vv show];
//                                }
//                            } else {
//
//                            }
//                        } else {
//                            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
//                            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
//                            UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
//                            [vv show];
//                        }
//                    }];
//
//                    [task resume];
                }else{
                    [NetTools postWithUrl:
                    [NSString stringWithFormat:@"http://%@/ldcy/OrderGoods/OrderGoods.asmx/UpdateOrder",str] pararms:dic
                         success:^(id  _Nonnull json) {
                            if ([[NSString stringWithFormat:@"%@",json[@"IsResult"]] isEqualToString:@"1"]) {
                                [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"remarkeeee"];
                                [[NSUserDefaults standardUserDefaults] synchronize];
                                self.a4.title = [NSString stringWithFormat:@"%@",json[@"Message"]];
                                [self.a4 show];
                            }else{
                                UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"%@",json[@"Message"]] delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                                [vv show];
                            }
                        } fail:^(NSError * _Nonnull error) {
                            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        //                            NSLog(@"服务器的错误原因:%@",str);
                            UIAlertView *vv = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
                            [vv show];
                            
                        }];
                }
                
            }
        }
        
    }
}
-(void)getEditData{
    NSString *str = [[NSUserDefaults standardUserDefaults] objectForKey:@"ipaddress"];
    if (str.length == 0) {
        // 请求头
//        NSString *accessPath = @"http://192.168.0.19:80/Api/OrderGoods/GetOrderDetails";
        NSString *accessPath = @"http://crm.zhenyea.com/Api/OrderGoods/GetOrderDetails";
        // 请求参数字典
        NSDictionary *params = @{
            @"strOrganizationNo":[NSString stringWithFormat:@"%@",self.userDic[@"OrganizationNo"]],
            @"strOrderID":self.oid,
            @"strUserId":[NSString stringWithFormat:@"%@",self.userDic[@"UserID"]],
            @"strPassword":[NSString stringWithFormat:@"%@",self.userDic[@"UserPass"]],
            @"strIMEI":[FCUUID uuidForVendor],
            @"strGroup":@"0"
        };
        
        //创建配置信息
        NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
        //设置请求超时时间：5秒
        configuration.timeoutIntervalForRequest = 5;
        //创建会话
        NSURLSession *session = [NSURLSession sessionWithConfiguration: configuration delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
        NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",accessPath]]];
        //设置请求方式：POST
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"content-Type"];
        [request setValue:@"application/json;charset=gb2312" forHTTPHeaderField:@"Accept"];
        
        //data的字典形式转化为data
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];
        //设置请求体
        [request setHTTPBody:jsonData];
        
        NSURLSessionDataTask * dataTask =[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            [SVProgressHUD dismiss];
            if (error == nil) {
                NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
                NSString *receiveStr = [[NSString alloc]initWithData:data encoding:encoding];
                NSData * aData = [receiveStr dataUsingEncoding:NSUTF8StringEncoding];
                NSError *errorr = nil;
                id response = [NSJSONSerialization JSONObjectWithData:aData options:NSJSONReadingMutableContainers error:&errorr];
                if ([response isKindOfClass:[NSDictionary class]]) {
                    // 请求成功数据处理
                    NSString *IsResult = [NSString stringWithFormat:@"%@",[response objectForKey:@"IsResult"]];
                    if ([IsResult isEqualToString:@"1"]) {
                        NSArray *a = response[@"Data"];
                        self.dataMarr = [a mutableCopy];
                        for (int i=0; i<self.dataMarr.count; i++) {
                            [self.tempArr addObject:[NSString stringWithFormat:@"%@",self.dataMarr[i][@"MaterialNum"]]];
                        }
                        [self.myTableView reloadData];
                        self.mbV.hidden = YES;
                        self.remarkBgV.hidden = YES;
                        self.remarkTV.text = self.editDicccc[@"OrderBZ"];
                        self.tvText = self.editDicccc[@"OrderBZ"];
                    }else{
                        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                        [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
                        [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@",response[@"Message"]]];
                    }
                } else {
                    NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                    NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                    NSLog(@"服务器的错误原因:%@",str);
                    [SVProgressHUD dismiss];
                }
            }else{
                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
                NSLog(@"服务器的错误原因:%@",str);
                [SVProgressHUD dismiss];
            }
        }];
        [dataTask resume];

//        AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
//
//        NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:accessPath parameters:params error:nil];
//        request.timeoutInterval = 10.f;
//        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
//        [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
//
//        NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
//            [SVProgressHUD dismiss];
//            if (!error) {
//                if ([responseObject isKindOfClass:[NSDictionary class]]) {
//                    // 请求成功数据处理
//                    NSString *IsResult = [NSString stringWithFormat:@"%@",[responseObject objectForKey:@"IsResult"]];
//                    if ([IsResult isEqualToString:@"1"]) {
//                        NSArray *a = responseObject[@"Data"];
//                        self.dataMarr = [a mutableCopy];
//                        for (int i=0; i<self.dataMarr.count; i++) {
//                            [self.tempArr addObject:[NSString stringWithFormat:@"%@",self.dataMarr[i][@"MaterialNum"]]];
//                        }
//                        [self.myTableView reloadData];
//                        self.mbV.hidden = YES;
//                        self.remarkBgV.hidden = YES;
//                        self.remarkTV.text = self.editDicccc[@"OrderBZ"];
//                        self.tvText = self.editDicccc[@"OrderBZ"];
//                    }else{
//                        [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
//                        [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
//                        [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@",responseObject[@"Message"]]];
//                    }
//                } else {
//                    
//                }
//            } else {
//                NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
//                NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
//                NSLog(@"服务器的错误原因:%@",str);
//                [SVProgressHUD dismiss];
//            }
//        }];
//
//        [task resume];
    }else{
        [NetTools postWithUrl:[NSString stringWithFormat:@"http://%@/ldcy/OrderGoods/OrderGoods.asmx/GetOrderDetails",str] pararms:[NSDictionary dictionaryWithObjectsAndKeys:self.oid,@"strOrderId",@"0",@"strGroup", nil]
         success:^(id  _Nonnull json) {
            [SVProgressHUD dismiss];
            if ([[NSString stringWithFormat:@"%@",json[@"IsResult"]] isEqualToString:@"1"]) {
                NSArray *a = json[@"Data"];
                self.dataMarr = [a mutableCopy];
                for (int i=0; i<self.dataMarr.count; i++) {
                    [self.tempArr addObject:[NSString stringWithFormat:@"%@",self.dataMarr[i][@"MaterialNum"]]];
                }
                [self.myTableView reloadData];
                self.mbV.hidden = YES;
                self.remarkBgV.hidden = YES;
                self.remarkTV.text = self.editDicccc[@"OrderBZ"];
                self.tvText = self.editDicccc[@"OrderBZ"];
            }else{
                [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
                [SVProgressHUD setMinimumDismissTimeInterval:0.2f];
                [SVProgressHUD showImage:[UIImage imageNamed:@""] status:[NSString stringWithFormat:@"%@",json[@"Message"]]];
            }
        } fail:^(NSError * _Nonnull error) {
            NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"];
            NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"服务器的错误原因:%@",str);
            [SVProgressHUD dismiss];
        }];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.oid.length>0?@"历史订单详情":[NSString stringWithFormat:@"%@货筐",self.houseDic[@"Warehouse"]];
    self.view.backgroundColor = RGBCOLOR(240, 240, 240);
    
    UIView *rightV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    UIButton *gwcBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    gwcBtn.frame = CGRectMake(5, 5, 40, 40);
    [gwcBtn setImage:[UIImage imageNamed:@"货框_04-05.png"] forState:UIControlStateNormal];
    gwcBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [gwcBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    [rightV addSubview:gwcBtn];
    gwcBtn.hidden = self.oid.length>0?YES:NO;
    self.gwcBtn = gwcBtn;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightV];
    
    UIView *leftV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    UIButton *gwcBtnl = [UIButton buttonWithType:UIButtonTypeCustom];
    gwcBtnl.frame = CGRectMake(0, 5, 30, 30);
    gwcBtnl.userInteractionEnabled = NO;
    [gwcBtnl setImage:[UIImage imageNamed:@"货框_03.png"] forState:UIControlStateNormal];
    gwcBtnl.imageView.contentMode = UIViewContentModeScaleAspectFit;
    UITapGestureRecognizer *t = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(leftAction:)];
    [leftV addGestureRecognizer:t];
//    [gwcBtnl addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    [leftV addSubview:gwcBtnl];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftV];
    
//    [self myTableView];
    
    [self tbheadGbV];
    
    
    UIView *bottomBGV = [[UIView alloc]initWithFrame:CGRectMake(0, SCREENHEIGHT-kTabBarHeight-20, SCREENWIDTH, kTabBarHeight+20)];
    bottomBGV.backgroundColor = RGBCOLOR(234, 234, 234);
    [self.view addSubview:bottomBGV];
    self.bottomBgV = bottomBGV;
    UIButton *lsddBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    lsddBtn.frame = CGRectMake(10, 15, (bottomBGV.frame.size.width-30)/2, 40);
    lsddBtn.layer.cornerRadius = 5;
//    lsddBtn.layer.borderWidth = 1;
//    lsddBtn.layer.borderColor = RGBCOLOR(108, 185, 251).CGColor;
    lsddBtn.backgroundColor = RGBCOLOR(108, 185, 251);
    [lsddBtn setTitle:@"备注" forState:UIControlStateNormal];
    [lsddBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bottomBGV addSubview:lsddBtn];
    self.lsddBtn = lsddBtn;
    [lsddBtn addTarget:self action:@selector(lsddBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    UIButton *ksdhBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    ksdhBtn.frame = CGRectMake(CGRectGetMaxX(lsddBtn.frame)+5, 15, lsddBtn.frame.size.width, 40);
    ksdhBtn.layer.cornerRadius = 5;
//    ksdhBtn.layer.borderWidth = 1;
//    ksdhBtn.layer.borderColor = RGBCOLOR(108, 185, 251).CGColor;
    ksdhBtn.backgroundColor = RGBCOLOR(108, 185, 251);
    [ksdhBtn setTitle:self.oid.length>0?@"提交":@"下单" forState:UIControlStateNormal];
    [ksdhBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bottomBGV addSubview:ksdhBtn];
    self.ksdhBtn = ksdhBtn;
    [ksdhBtn addTarget:self action:@selector(ksdhBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    if (self.oid.length > 0) {
        self.isreturn = NO;
        [self getEditData];
    }
    
    [self.myTableView reloadData];
}
-(void)leftAction:(UITapGestureRecognizer *)item{
    if (self.oid.length > 0) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"xiadanle" object:nil];
        if (self.isreturn == NO) {
            for (int i=0; i<self.dataMarr.count; i++) {
                NSDictionary *temp1 = self.dataMarr[i];
                NSString *tempstr1 = [NSString stringWithFormat:@"%@",temp1[@"MaterialNum"]];
                NSString *tempstr2 = self.tempArr[i];
                if (!([tempstr1 floatValue] == [tempstr2 floatValue])) {
                    self.isreturn = YES;
                    break;
                }
            }
        }
        if (self.isreturn == YES) {
            a5 = [[UIAlertView alloc] initWithTitle:nil message:@"订单已变化，确定放弃修改吗？" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
            a5.delegate = self;
            [a5 show];
        }else{
            [self.navigationController popViewControllerAnimated:YES];
        }
    }else{
        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeee" object:nil];
        [[NSUserDefaults standardUserDefaults] setObject:self.remarkTV.text forKey:@"remarkeeee"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [self.navigationController popViewControllerAnimated:YES];
    }
}
-(void)ksdhBtnAction:(UIButton *)btn{

    a3 = [[UIAlertView alloc] initWithTitle:nil message:self.oid.length>0?@"确定修改订单么？":@"确定下单么？" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
    a3.delegate = self;
    [a3 show];
}
-(void)lsddBtnAction:(UIButton *)btn{
    //备注
    self.mbV.hidden = NO;
    self.remarkBgV.hidden = NO;
    [self.remarkTV becomeFirstResponder];
    CGRect r = self.remarkBgV.frame;
    r.origin.y = kNavBarAndStatusBarHeight;
    self.remarkBgV.frame = r;
}
#pragma mark <UITableViewDelegate,UITableViewDataSource>
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataMarr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *idf = @"CargoBoxTableViewCell";
    CargoBoxTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:idf];
    if (!cell) {
        cell = [[CargoBoxTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:idf];
    }
    cell.dic = self.dataMarr[indexPath.row];
    for (int i=0; i<self.dataMarr.count; i++) {
        if ([[NSString stringWithFormat:@"%@",cell.dic[@"MaterialID"]] isEqualToString:[NSString stringWithFormat:@"%@",self.dataMarr[i][@"MaterialID"]]]) {
            cell.cdxdbmL.text = [NSString stringWithFormat:@"%@",self.dataMarr[i][@"MaterialNum"]];
            cell.pluseBtn.selected = YES;
            cell.jianBtn.hidden = NO;
            cell.jianBtn.selected = YES;
            break;
        }
        if (i==self.dataMarr.count-1) {
            cell.cdxdbmL.text = @"0";
            cell.pluseBtn.selected = NO;
            cell.jianBtn.hidden = YES;
        }
    }
    
    __weak typeof(self) weakSelf = self;
    __weak typeof(cell) weakCell = cell;
    cell.jianBlock = ^(NSString *num) {//消除
        weakSelf.wlLCell = weakCell;
        weakSelf.wlLCellIndexPath = indexPath;
        
        a2 = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@",weakCell.dic[@"MaterialName"]] message:@"确定要删除么？" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        a2.delegate = self;
        [a2 show];
        
    };
    cell.pluseBlock = ^(NSString *num) {
        weakSelf.isTffff = YES;
        weakSelf.mbV.hidden = NO;
        weakSelf.srBgV.hidden = NO;
        weakSelf.wlLCell = weakCell;
        weakSelf.wlL.text = [NSString stringWithFormat:@"%@",weakCell.dic[@"MaterialName"]];
        if (![weakCell.cdxdbmL.text isEqualToString:@"0"]) {
            weakSelf.srBgVTF.text = weakCell.cdxdbmL.text;
        }


        [weakSelf.srBgVTF becomeFirstResponder];
    };
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
//1.创建plist文件
-(void)creatPlist{
    //1.创建plist文件的路径(plist文件要存储的本地路径)
    NSString *filePath = [NSHomeDirectory() stringByAppendingString:@"/Documents/myPlist.plist"];
   
    //2.准备存储的数据
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
   
    [dic setValue:self.houseDic forKey:@"ckHouse"]; //仓库选择
   
    [dic setValue:self.userDic forKey:@"userData"];//用户数据
   
    [dic setValue:self.dataMarr forKey:@"numDataMarr"];//已点物料
   
    //3.将准备好的数据存储到plist文件中
    [dic writeToFile:filePath atomically:YES];
}
@end
